Skip to content

Deprecate partially supported callables #7446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Sep 1, 2021

This deprecates callables that are accepted by call_user_func($callable) but not $callable():

"self::method"
"parent::method"
"static::method"
["self", "method"]
["parent", "method"]
["static", "method"]
["Foo", "Bar::method"]
[new Foo, "Bar::method"]

RFC: https://wiki.php.net/rfc/deprecate_partially_supported_callables

@nikic nikic added the RFC label Sep 1, 2021
@nikic nikic force-pushed the callable-deprecation branch from e2aae61 to 3af29f1 Compare September 2, 2021 08:49
@nikic nikic changed the title Deprecate self/parent/static in callables Deprecate partially supported callables Sep 2, 2021
@ta-tikoma
Copy link

I would like to make the language better and I have a proposal for a long time: make a new spelling to indicate the method and consider it the only correct one.
Example:

class Foo
{
    int $moo;

    function bar()
    {
        ...
    }
}

Line

Foo::method->bar

interpret as

[Foo::class, 'bar']

Pros:

  • easier readability: it will be clear that this is an indication of a method, and not a strange array
  • for ide it will be easier to understand what is happening now and suggest the name of the method.

Perhaps, if it was positively accepted by the community, it would open up possibilities such as specifying a typehint for Closure. And also, by analogy, you can make an indication of properties of class, having received the above described advantages.

Foo::property->moo

@nikic
Copy link
Member Author

nikic commented Sep 26, 2021

@ta-tikoma This sounds like https://wiki.php.net/rfc/first_class_callable_syntax, which is part of PHP 8.1.

@ta-tikoma
Copy link

@ta-tikoma This sounds like https://wiki.php.net/rfc/first_class_callable_syntax, which is part of PHP 8.1.

that's right, I'm wrong, with a different interpretation

@nikic nikic force-pushed the callable-deprecation branch from abc9252 to 9270e48 Compare October 6, 2021 08:26
@nikic nikic force-pushed the callable-deprecation branch from 9270e48 to 0ca1a69 Compare October 8, 2021 13:59
@ElvenSpellmaker
Copy link

Is it true this removes the ability to make deferred calls in those forms listed from PHP entirely?

I totally get the bottom two being removed as they're pretty nonsensical, but the top 6 don't currently have any other way of representing them, even if it's "often" undesired behaviour it might not be and seems odd to remove such a dynamic way of referencing a method call from a pretty dynamic language just because it might not be what people intended...

@nikic
Copy link
Member Author

nikic commented Oct 14, 2021

@ElvenSpellmaker Please see https://wiki.php.net/rfc/deprecate_partially_supported_callables#backward_incompatible_changes for suggested alternative spellings.

If by "deferred calls" you mean passing "self::foo" to a different class, such that "self" refers to a different class than self, then yes, this is being removed with prejudice.

@driesvints
Copy link

Is there any easy way to figure out where these calls are being made? We're trying to get a working PHP 8.2 build for Laravel but we can't figure out where all the failures from this PR are coming: https://github.com/laravel/framework/runs/8183443527?check_suite_focus=true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants